import { Component, Emit, Prop } from 'vue-property-decorator';
import { BaseController, PageVO, DialogVO, YhRspType, YhResponseData, DateUtils } from '@yhfin/biz';
import InvestmentQuery from '@/pages/investment/view/Investment-query.vue';
import InvestmentUpload from '@/pages/investment/view/Investment-upload.vue';
import OperationRecord from '@/pages/investment/view/operation-record.vue';
import { downLoadFile } from '@/utils/request';
import RiskTableLayout from '@/common/components/risk-table-layout.vue';
import { InvestMentReq } from '../model/InvestMentReq';
import InvestmentService from '../service/InvestmentService';
import RiskBaseController from '@/common/api/RiskBaseController';
@Component({
    components: { InvestmentQuery, InvestmentUpload, OperationRecord, RiskTableLayout },
    watch: {},
})
export default class InvestmentListController extends RiskBaseController {
    private reqVO: InvestMentReq = new InvestMentReq();
    private service: InvestmentService = new InvestmentService();
    private selection = [];
    // 固定字段列表tableColumns
    mounted() {
        this.tableName = 'TR_HT_INVESTMENT_SUPERVISION';
        this.tableColumns = [
            { id: 'fundCode1', content: '产品代码(O32)', field: 'fundCode1', fixed: 'left', minWidth: '150px', align: 'left' },
            { id: 'fundName', content: '产品名称', field: 'fundName', fixed: 'left', minWidth: '150px', align: 'left' },
            { id: 'controlType', content: '控制类型', field: 'controlType', minWidth: '120px', align: 'left' },
            { id: 'controlGrade', content: '来源', field: 'controlGrade', width: '60px', align: 'left' },
            { id: 'fundGpName', content: '风控基金组', field: 'fundGpName', minWidth: '120px', align: 'left' },
            { id: 'assetType', content: '资产类型', field: 'assetType', minWidth: '120px', align: 'left' },
            { id: 'entryName', content: '风控条款内容', field: 'entryName', minWidth: '200px', align: 'left' },
            { id: 'definition', content: '释义', field: 'definition', minWidth: '200px', align: 'left' },
            { id: 'remarks', content: '备注', field: 'remarks', minWidth: '200px', align: 'left' },
            { id: 'hsEntryCode', content: '恒生系统', field: 'hsEntryCode', width: '100px', align: 'left' },
            { id: 'hsEntryName', content: '恒生系统风险说明', field: 'hsEntryName', minWidth: '200px', align: 'left' },
            { id: 'htEntryCode', content: '衡泰系统', field: 'htEntryCode', width: '100px', align: 'left' },
        ];
        this.fixedFieldList = [{ id: 'fundCode1', content: '产品代码(O32)', field: 'fundCode1', fixed: 'left', minWidth: '100px', align: 'left' }];
        this.queryLayout();
        this.search();
    }
    query(reqVO: InvestMentReq) {
        this.reqVO = JSON.parse(JSON.stringify(reqVO));
        this.search();
    }

    public search() {
        this.pageQuery(this.pageVO);
    }

    async pageQuery(pageVO: PageVO) {
        this.reqVO.paging.currentPage = pageVO.pageNum;
        this.reqVO.paging.pageSize = pageVO.pageSize;
        this.service.pageQuery(this.reqVO).then(res => {
            console.info(this.showFieldList);
            this.$nextTick(() => {
                this.$set(this.pageVO, 'list', res.list);
                this.$set(this.pageVO, 'total', res.total);
                this.$set(this.pageVO, 'pageNum', pageVO.pageNum);
                this.$set(this.pageVO, 'pageSize', pageVO.pageSize);
            });
        });
    }

    // 导入
    upload_() {
        this.$refs.investmentUpload.open();
    }

    // 导出
    export_() {
        const tableColumns = this.$refs.refTable.getColumns();
        const columns = [];
        tableColumns.forEach(column => {
            if (column.property && column.title) {
                columns.push({ id: column.property, content: column.title });
            }
        });
        this.reqVO.columns = columns;
        downLoadFile({
            url: '/investMent/export',
            method: 'post',
            data: this.reqVO,
            loading: true,
            loadingMsg: '正在准备导出，请稍后··· ···',
        });
    }

    // 删除
    delete_() {
        this.$confirm('确定删除如下数据吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }).then(() => {
            const cloneData = JSON.parse(JSON.stringify(this.reqVO));
            cloneData.resultIdList = this.selection.map(e => e.resultId);
            this.service.delete(cloneData).then(res => {
                this.selection = [];
                this.search();
            });
        });
    }

    // 操作记录
    operationRecord() {
        this.$refs.operationRecord.open();
    }

    selectionChange(table) {
        this.selection = table.selection;
    }

    async onSubmit() {
        this.queryLayout();
    }

    handleDownTemp(): void {
        downLoadFile({
            url: '/investMent/downloadFile',
            method: 'post',
            data: {},
        });
    }
}
